/*
 * @LastEditors: w
 */
// `<script src="https://screeps-cn.gitee.io/screeps-chinese-pack-release/main.js" async defer></script>`
import { errorMapper } from './modules/errorMapper'
import { sayHello } from './modules/utils'
import rule from './modules/rule'
/**
 * 全局统计信息扫描器
 * 负责搜集关于 cpu、memory、GCL、GPL 的相关信息
 */
 const stateScanner = function () {
    // 每 20 tick 运行一次
    if (Game.time % 20) return
    if (!Memory.stats) Memory.stats = {}
    
    // 统计 GCL / GPL 的升级百分比和等级
    Memory.stats.gcl = (Game.gcl.progress / Game.gcl.progressTotal) * 100
    Memory.stats.gclLevel = Game.gcl.level
    Memory.stats.gpl = (Game.gpl.progress / Game.gpl.progressTotal) * 100
    Memory.stats.gplLevel = Game.gpl.level
    // CPU 的当前使用量
    Memory.stats.cpu = Game.cpu.getUsed()
    // bucket 当前剩余量
    Memory.stats.bucket = Game.cpu.bucket
}
// Game.spawns['Spawn1'].spawnCreep( [WORK,WORK, CARRY, MOVE], 'Harvester1' );
export const loop =function () {
    rule.upgrader.create('1312212')
    for(var name in Game.creeps) {
        var creep = Game.creeps[name];
        if(creep.memory.role == 'harvester') {
            rule.harvester.run(creep);
        }else{
            // rule.harvester.run(creep);
        }
        if(creep.memory.role == 'upgrader') {
            rule.upgrader.update(creep);
        }
    }
    // 统计全局资源使用
    // stateScanner()
}






// export const loop = errorMapper(() => {
//     for(var name in Game.creeps) {
//         var creep = Game.creeps[name];
//         harvester.run(creep);
//     }
//     // 统计全局资源使用
//     // stateScanner()
// })